﻿using Infra.Tools.Logging;
using System;
using System.Linq.Expressions;

namespace BLL.Service.Basis
{
    public class TransactionalKernelService<T> : Kernel<T>, ITransactional<T>
        where T : class, new()
    {
        #region Constructors
        public TransactionalKernelService(IRepositoryFactory repositoryfactory, ILogger logger)
            : base(repositoryfactory, logger)
        { }
        #endregion

        public override T Insert(T entity)
        {
            var result = base._repository.Insert(entity);

            return result;
        }

        public override void Delete(T entity)
        {
            base._repository.Delete(entity);
        }

        public override void Delete(Expression<Func<T, bool>> predicate)
        {
            base._repository.Delete(predicate);
        }

        public override void Update(T entity)
        {
            base._repository.Update(entity);
        }

        public override void Update(Expression<Func<T, bool>> predicate, Action<T> action)
        {
            base._repository.Update(predicate, action);
        }

        public override T InsertIfNotExist(T entity)
        {
            return base._repository.InsertIfNotExist(entity);
        }

        public override T InsertIfNotExist(Expression<Func<T, bool>> predicate, T entity)
        {
            return base._repository.InsertIfNotExist(predicate, entity);
        }

        public override T InsertOrUpdate(Expression<Func<T, bool>> predicate, T entity, Action<T> action)
        {
            return base._repository.InsertOrUpdate(predicate, entity, action);
        }

        public override void Restore(T entity)
        {
            base._repository.Restore(entity);
        }

        public void SaveChanges()
        {
            base._repository.SaveChanges();
        }
    }
}
